<template>
  <div class="goods-relevant">
    <div class="header">
      <i class="icon" />
      <span class="title">{{ goodsid ? "同类商品推荐" : "猜你喜欢" }}</span>
    </div>
    <!-- 此处使用改造后的xtx-carousel.vue -->
    <carousel :tong="tong"></carousel>
  </div>
</template>

<script>
import carousel from "./carousel.vue";
import { findRelGoods } from "@/utils/Api/NavText";
export default {
  components: { carousel },
  props: ["goodsid"],
  data() {
    return {
      slides: [],
      list: {
        name: null,
        price: null,
        picture: null,
      },
    };
  },
  methods: {
    async lists() {
      let res = await findRelGoods(this.goodsid);
      this.slides = res.result;

      // console.log(this.slides);
    },
  },
  mounted() {
    this.lists();
  },
  computed: {
    tong() {
      var arr = []
      this.slides.forEach((item) => {
        this.list.name = item.name;
        this.list.picture = item.picture;
        this.list.price = item.price;
        arr.push({...this.list})
      });
      return arr
    },
  }, 
};
</script>

<style scoped lang="scss">
@import "@/assets/css/color.scss";
.goods-relevant {
  background: #fff;
  min-height: 460px;
  margin-top: 20px;
  .header {
    height: 80px;
    line-height: 80px;
    padding: 0 20px;
    .title {
      font-size: 20px;
      padding-left: 10px;
    }
    .icon {
      width: 16px;
      height: 16px;
      display: inline-block;
      border-top: 4px solid $xtxColor;
      border-right: 4px solid $xtxColor;
      box-sizing: border-box;
      position: relative;
      transform: rotate(45deg);
      &::before {
        content: "";
        width: 10px;
        height: 10px;
        position: absolute;
        left: 0;
        top: 2px;
        background: lighten($xtxColor, 40%);
      }
    }
  }
}
</style>
